import React from 'react';

import { FormTemplate } from '../../Utils/FormTemp'
import { useEventEmitter } from 'ahooks';
import { useRequest } from 'alova';
import { Http } from '../../Api';



const FormAdded = ({ data }) => {
    const { record, columns } = data
    const { request_api, successBack, errorBack } = record
    const { send } = useRequest(({ url, params }) => Http({ url, params }), { immediate: false })
    const FormEvent = useEventEmitter()
    FormEvent.useSubscription(val => {
        const { type, data } = val
        if (type === 'Added') {
            send({ url: request_api, params: data })
                .then(() => { console.log('[添加成功]', successBack) })
                .catch(() => { console.log('[添加失败]', errorBack) })
        }
    })

    return (
        <div className='FormAdded'>
            <FormTemplate columns={columns} ModalEvent={FormEvent} />
        </div>
    );
};

export default FormAdded;